package com.hbnu.mapper;

import com.hbnu.pojo.Category;
import com.hbnu.pojo.Good;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;
@Mapper
public interface GoodsMapper {
    @Select("select * from category")
    List<Category> getCategoryList();

    @Select("select * from good")
    List<Good> getGoodList();
    @Select("select * from good where cid=#{cid}")
    List<Good> getGoodListByCid(String cid);

    @Select("select * from good where (gid like '%' #{content} '%' ) or (gname like '%' #{content} '%' )")
    List<Good> getGoodListByContent(String content);

    @Select("select * from good where state=#{state} ")
    List<Good> getGoodListByState(Integer state);

    @Select("select * from good where cid=#{cid} and (gid like '%' #{content} '%' or gname like '%' #{content} '%'  )")
    List<Good> getGoodListByCidAndContent(String cid,String content);

    @Select("select * from good where cid=#{cid} and state=#{state}")
    List<Good> getGoodListByCidAndState(String cid,Integer state);

    @Select("select * from good where state=#{state} and (gid like '%' #{content} '%' or gname like '%' #{content} '%' )")
    List<Good> getGoodListByStateAndContent(String content,Integer state);

    @Select("select * from good where cid=#{cid} and state=#{state} and (gid like '%' #{content} '%' or gname like '%' #{content} '%' )")
    List<Good> getGoodListByContentStateCid(String cid,String content,Integer state);

    @Insert("insert into category (cid, cname) value (#{cid},#{cname})")
    void insertCategory(String cid,String cname);

    @Insert("insert into good (gid, gname, cid, price, `desc`, src, num, state) " +
            "value (#{gid},#{gname},#{cid},#{price},#{desc},#{src},#{num},#{state})")
    void insertGood(String gid,String gname,String cid,String price,String desc,String src,Integer num,Integer state);

    @Update("update good set gname=#{gname} where gid=#{gid}")
    void updateGoodGname(String gname,String gid);

    @Update("update good set price=#{price} where gid=#{gid}")
    void updateGoodPrice(String price,String gid);

    @Update("update good set `desc`=#{desc} where gid=#{gid}")
    void updateGoodDesc(String desc,String gid);

    @Update("update good set src=#{src} where gid=#{gid}")
    void updateGoodSrc(String src,String gid);

    @Update("update good set num=#{num} where gid=#{gid}")
    void updateGoodNum(Integer num,String gid);

    @Update("update good set state=#{state} where gid=#{gid}")
    void updateGoodState(Integer state,String gid);
}
